package com.apping.viewpager;

import java.util.ArrayList;

import android.app.Activity;
import android.app.ActivityManager;
import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;

public class WelcomeAtv extends Activity {

	private ViewPager mViewPager;
	
	private ImageView mPage0;
	private ImageView mPage1;
	private ImageView mPage2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.welcome);
		
		mViewPager = (ViewPager)findViewById(R.id.welcome_viewpager);
		
		mViewPager.setOnPageChangeListener(new MyOnPageChangeListener());
		mPage0 = (ImageView)findViewById(R.id.page0);
		mPage1 = (ImageView)findViewById(R.id.page1);
		mPage2 = (ImageView)findViewById(R.id.page2);
		
		LayoutInflater mLi = LayoutInflater.from(this);
		View view0 = mLi.inflate(R.layout.wel_gallery_zero, null);
		View view1 = mLi.inflate(R.layout.wel_gallery_one, null);
		View view2 = mLi.inflate(R.layout.wel_gallery_two, null);
		
		final ArrayList<View> views = new ArrayList<View>();
		views.add(view0);
		views.add(view1);
        views.add(view2);
        
        final ArrayList<String> titles = new ArrayList<String>();
        titles.add("tab0");
        titles.add("tab1");
        titles.add("tab2");
        
        MyPageAdapter mPagerAdapter = new MyPageAdapter(views,titles);
        mViewPager.setAdapter(mPagerAdapter);
        
        view2.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				Intent intent=new Intent(WelcomeAtv.this,StartAtv.class);
				startActivity(intent);
				finish();
			}
		});
	}
	
	public class MyOnPageChangeListener implements OnPageChangeListener {

		@Override
		public void onPageScrollStateChanged(int arg0) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void onPageSelected(int page) {
			switch(page) {
			case 0:
				mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
				mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
				break;
			case 1:
				mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
				mPage0.setImageDrawable(getResources().getDrawable(R.drawable.page));
				mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page));
				break;
			case 2:
				mPage2.setImageDrawable(getResources().getDrawable(R.drawable.page_now));
				mPage1.setImageDrawable(getResources().getDrawable(R.drawable.page));
				break;
			}
		}
		
	}
}
